<%--
  Created by IntelliJ IDEA.
  User: 18042986105
  Date: 2021/6/14
  Time: 17:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <style type="text/css">
        .layui-form{
            margin-right:200px;
            margin-top:50px;
            margin-left:40px;
        }
    </style>
</head>
<body>
<script src="../../layui/layui.js" charset="utf-8"></script>
<form class="layui-form" id="rform">
    <div class="layui-form-item">
        <label class="layui-form-label">输入框</label>
        <div class="layui-input-block">
            <input type="text" name="username" required  lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码框</label>
        <div class="layui-input-inline">
            <input type="text" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">选择分类</label>
        <div class="layui-input-block">
            <select name="auth" lay-verify="required" class="sel">
            <option value=""></option>
                <option value="0">普通用户</option>
                <option value="1">电工</option>
                <option value="2">水工</option>
                <option value="3">木工</option>
                <option value="4">食堂管理员</option>
                <option value="5">宿舍管理员</option>
                <option value="6">教学楼管理员</option>
                <option value="7">其它管理员</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo" onclick="addUser()">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary hhhh">重置</button>
        </div>
    </div>
</form>

<script>
    //Demo
    layui.use('form', function(){
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function(data){
            layer.msg(JSON.stringify(data.field));
            return false;
        });
    });

    function  addUser() {
        $.ajax({
            url:"/regist/adds",
            data:$('#rform').serialize(),
            method:'post',
            success: function (result) {
                if (result.status) {
                    alert('成功');
                    $('.hhhh')[0].reset();
                }
                else {
                    alert(result.message)
                }

            }
        })
    }
</script>
</body>
</html>
